home *** CD-ROM | disk | FTP | other *** search
- Path: sierra.net!usenet
- From: TGColwell <snowbull@sierra.net>
- Newsgroups: comp.lang.c++
- Subject: Returning ref to object - is this code invalid?
- Date: Sun, 14 Jan 1996 09:05:28 -0800
- Organization: Sierra-Net
- Message-ID: <30F937D8.12D2@sierra.net>
- NNTP-Posting-Host: 204.94.232.59
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b5 (WinNT; I)
-
- Does the following code create a dangling reference?
-
- class vector
- { private: float x,y,z;
- public: //c'tors & functions
- };
-
- class face
- { private: vector v1, v2, v3;
- public:
- vector& get_vtx_1() const;
- }
-
- vector& face::get_vtx_1() const //returns reference to vector
- { return v1;
- }
-
- void main()
- {
- face ff('constructor parameters);
- vector vv = ff.get_vtx_1();
- }
-
- I'm wondering if the return of a reference to v1 will invalidate
- my program since v1 goes out of scope when get_vtx_1() returns,
- or does v1 stay in scope since ff is not deleted?
-
- Any input is appreciated!
-
- -TC
-